#include "userslistwidget.h"
#include <QVBoxLayout>
#include <QRadioButton>

UsersListWidget::UsersListWidget(UserList* list, QWidget *parent) :
    QWidget(parent), m_list(list)
{
    connect(&m_list,SIGNAL(currentIndexChanged(int)),this,SIGNAL(currentIndexChanged(int)));
    connect(&m_filter,SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(setFilter(QAbstractButton*)));
    QVBoxLayout* main = new QVBoxLayout;
    main->setContentsMargins(0,0,0,0);
    QHBoxLayout* hlay = new QHBoxLayout;
    QRadioButton* btn = new QRadioButton(tr("Все"),this);
    btn->setChecked(true);
    m_filter.addButton(btn);
    hlay->addWidget(btn);
    foreach(QString name, list->units())
    {
        btn = new QRadioButton(name,this);
        m_filter.addButton(btn);
        hlay->addWidget(btn);
    }
    main->addLayout(hlay);
    main->addWidget(&m_list);
    setLayout(main);
}

void UsersListWidget::setUsersList(UserList *list)
{
    m_list.setUsersList(list);
}

void UsersListWidget::uninclude(const int &uid)
{
    m_list.uninclude(uid);
}

void UsersListWidget::refresh()
{
    m_list.refresh();
}

void UsersListWidget::setUser(const int &Index)
{
    m_list.setUser(Index);
}

QVariant UsersListWidget::itemData(int index, int role)
{
    return m_list.itemData(index,role);
}

int UsersListWidget::currentIndex() const
{
    return m_list.currentIndex();
}

void UsersListWidget::setFilter(QAbstractButton *button)
{
    m_list.setFilter(button->text());
}
